using System;
using System.Collections;
using System.Threading;
using System.Web;
using Sedna.Core.Common;
using Sedna.Core.Controller.Common;
using log4net;

namespace Sedna.Core.Controller
{
	public class SessionExceptionHandler : AbstractExceptionHandler
	{

		private ILog log = LogManager.GetLogger(typeof(SessionExceptionHandler));

        private String redirectUrl;

	    public string RedirectUrl
	    {
	        set { redirectUrl = value; }
	    }

	    public SessionExceptionHandler()
		{
		}



		public override IActionResult HandleException(IExecutionContext executionContext, Exception exception)
		{
			if(exception is ThreadAbortException)
			{
				return new ActionResult(successStatus);
			}
		    executionContext.SetScopedValue("infrastructure.LastException", exception, Scope.Session);
			executionContext["infrastructure.LastException"] = exception;
			log.Warn("handled exception", exception);
            
		    HttpContext.Current.Response.Redirect(redirectUrl);
            
		    return new ActionResult("exception");
		}
	}
}
